$(function() {
	//验证用户输入的工资范围
	$("#salFrom-in-searchForm").blur(function() {
		closeAlert();
		var salFrom = $("#salFrom-in-searchForm");
		var salTo = $("#salTo-in-searchForm");
		var regExp = /^[0-9]+.?[0-9]*$/;
		if (salFrom.val() == "") {
			salFrom.val("*");
		} else if (!regExp.test(salFrom.val())) {
			showValidateMsg($("#salFrom-in-searchForm"), "请输入数字", false);
			//alertInfo($(".alertContainer"),"工资区间只能输入数字");
			return;
		} else if (regExp.test(salTo.val())) {
			var salFromValue = parseFloat(salFrom.val());
			var salToValue = parseFloat(salTo.val());
			if (salFromValue > salToValue) {
				showValidateMsg($("#salFrom-in-searchForm"), "工资区间不合法", false);
				//alertInfo($(".alertContainer"),"工资区间不合法");
				return;
			}
		}
		showValidateMsg($("#salFrom-in-searchForm"), "", true);
		showValidateMsg($("#salTo-in-searchForm"), "", true);
	});
	$("#salTo-in-searchForm").blur(function() {
		closeAlert();
		var salFrom = $("#salFrom-in-searchForm");
		var salTo = $("#salTo-in-searchForm");
		var regExp = /^[0-9]+.?[0-9]*$/;
		if (salTo.val() == "") {
			salTo.val("*");
		} else if (!regExp.test(salTo.val())) {
			showValidateMsg($("#salTo-in-searchForm"), "请输入数字", false);
			//alertInfo($(".alertContainer"),"工资区间只能输入数字");
			return;
		} else if (regExp.test(salFrom.val())) {
			var salFromValue = parseFloat(salFrom.val());
			var salToValue = parseFloat(salTo.val());
			if (salFromValue > salToValue) {
				showValidateMsg($("#salFrom-in-searchForm"), "工资区间不合法", false);
				//alertInfo($(".alertContainer"),"工资区间不合法");
				return;
			}
		}
		showValidateMsg($("#salFrom-in-searchForm"), "", true);
		showValidateMsg($("#salTo-in-searchForm"), "", true);
	});
	
	//用户点击重置按钮
	$("#resetButton").click(function() {
		$('#searchForm')[0].reset();
		showValidateMsg($("#salFrom-in-searchForm"), "", true);
		showValidateMsg($("#salTo-in-searchForm"), "", true);
	});
	
	//用户点击搜索按钮
	$("#searchButton").click(function() {
		if ($("#searchForm input.error").length == 0) {
			closeAlert();
			var depName = $("#depName-in-searchForm").val();
			var empNo = $("#empNo-in-searchForm").val();
			
			var dateRange = $("#dateRange-in-searchForm").val();
			var month = new Array();
			if (dateRange != "") {
				month = dateRange.split(" - ");
			} else {
				month[0] = "*";
				month[1] = "*";
			}
			
			var salFrom = $("#salFrom-in-searchForm").val();
			var salTo = $("#salTo-in-searchForm").val();
			var offset = 0;
			
			search(depName, empNo, month[0], month[1], salFrom, salTo, offset, true);
		}
	});
	
	//发送异步搜索请求
	var search = function(depName, empNo, startMonth, endMonth, salFrom, salTo, offset, refresh) {
		$.post("fixedSalary/searchFixedSal", 
				{"depName":depName, "empNo":empNo, "startMonth":startMonth, "endMonth":endMonth,"salFrom":salFrom, "salTo":salTo, "offset":offset},
				function(response) {
					//console.log(response);
					//var jsonData = eval('('+response+')');
					var jsonData = eval(response);
					
					if (jsonData.statusCode != "200") {
						alertInfo($(".alertContainer"), jsonData.message);
						$("#resultTable").css("display", "none");
					} else {
						var result = jsonData.response;
						if(result.total == 0){
							alertInfo($(".alertContainer"), "没有相关固定工资信息");
							$("#resultTable").css("display", "none");
						} else {
							if(refresh){
								closeAlert();
							}
							$("#depName-in-resultTable").val(depName);
							$("#empNo-in-resultTable").val(empNo);
							$("#startMonth-in-resultTable").val(startMonth);
							$("#endMonth-in-resultTable").val(endMonth);
							$("#salFrom-in-resultTable").val(salFrom);
							$("#salTo-in-resultTable").val(salTo);
							$("#pageSize-in-resultTable").val(result.size);
							loadSearchResult(result);
						}
					}
					
					$(".editButton").click(function() {
						closeAlert();
						var rowId = $(this).attr("rowId");
						$("#editModal").modal('show'); 
						loadEditModel(rowId, result);
					});
					$(".importButton").click(function() {
						closeAlert();
						$("#importModal").modal('show'); 
						loadImportModel(result);
					});
				}
		);
	};
	
	//显示搜索表格
	var loadSearchResult = function(searchResult) {
		$(".tableHead").html("");
		$(".tableRow").html("");
		
		//var jsonData = eval('('+searchResult+')');
		//var jsonData = eval(searchResult);
		var resultList = searchResult.datas;
		
		//加载表头
		$(".tableHead").append("<th>部门名</th>");
		$(".tableHead").append("<th>员工编号</th>");
		$(".tableHead").append("<th>员工姓名</th>");
		$(".tableHead").append("<th>月份</th>");
		var fixedSalList = resultList[0].salItemName;
		for (var i = 0; i < fixedSalList.length; i++) {
			$(".tableHead").append("<th>" + fixedSalList[i] + "</th>");
		}
		$(".tableHead").append("<th><button class='importButton btn btn-xs btn-info'>" +
		   					   "<i class='ace-icon fa fa-plus bigger-120'></i></button></th>");
		
		//加载行
		for (var i = 0; i < resultList.length; i++) {
			var row = "<tr id='" + i + "'>" + "<td>" + resultList[i].depName +"</td>" + 
					  "<td>" + resultList[i].empNo +"</td>" + "<td>" + resultList[i].empName +"</td>" + 
					  "<td>" + resultList[i].month +"</td>";
			var salaryList = resultList[i].salItemValue;
			for (var j = 0; j < salaryList.length; j++) {
				row += "<td>" + salaryList[j] +"</td>"
			}
			row += "</tr>";
			$(".tableRow").append(row);
			$("#" + i).append("<td><div class='hidden-sm hidden-xs btn-group'><button class='editButton btn btn-xs btn-info'" +
											  "rowId='" + i + "'><i class='ace-icon fa fa-pencil bigger-120'></i></button></div></td>");
		}
		
		var pageNum = Math.ceil(searchResult.offset / searchResult.size) + 1;
		$(".pageNum").html(pageNum);
		var totalPageNum = Math.ceil(searchResult.total / searchResult.size);
		$(".totalPageNum").html(totalPageNum);
		$(".totalRowNum").html(searchResult.total);
		$(".pageChange").attr("colspan", fixedSalList.length + 5);
		$(".pageChange").css("text-align", "center");
		$("#resultTable").css("display", "");
	};
	
	//点击首页
	$(".firstPage").click(function() {
		var depName = $("#depName-in-resultTable").val();
		var empNo = $("#empNo-in-resultTable").val();
		var startMonth = $("#startMonth-in-resultTable").val();
		var endMonth = $("#endMonth-in-resultTable").val();
		var salFrom = $("#salFrom-in-resultTable").val();
		var salTo = $("#salTo-in-resultTable").val();
		search(depName, empNo, startMonth, endMonth, salFrom, salTo, 0, true);
	});
	
	//点击上一页
	$(".prePage").click(function() {
		var depName = $("#depName-in-resultTable").val();
		var empNo = $("#empNo-in-resultTable").val();
		var startMonth = $("#startMonth-in-resultTable").val();
		var endMonth = $("#endMonth-in-resultTable").val();
		var salFrom = $("#salFrom-in-resultTable").val();
		var salTo = $("#salTo-in-resultTable").val();
		var offset = parseInt($(".pageNum").html()) - 1;
		var pageSize = parseInt($("#pageSize-in-resultTable").val());
		if (offset <= 0) {
			alertInfo($(".alertContainer"),"已经是第一页");
		} else {
			search(depName, empNo, startMonth, endMonth, salFrom, salTo, (offset - 1) * pageSize, true);
		}
	});
	
	//点击下一页
	$(".nextPage").click(function() {
		var depName = $("#depName-in-resultTable").val();
		var empNo = $("#empNo-in-resultTable").val();
		var startMonth = $("#startMonth-in-resultTable").val();
		var endMonth = $("#endMonth-in-resultTable").val();
		var salFrom = $("#salFrom-in-resultTable").val();
		var salTo = $("#salTo-in-resultTable").val();
		var offset = parseInt($(".pageNum").html()) - 1;
		var totalPageNum = parseInt($(".totalPageNum").html());
		var pageSize = parseInt($("#pageSize-in-resultTable").val());
		if (offset == totalPageNum - 1) {
			alertInfo($(".alertContainer"),"已经是最后一页");
		} else {
			search(depName, empNo, startMonth, endMonth, salFrom, salTo, (offset + 1) * pageSize, true);
		}
	});
	
	//点击尾页
	$(".lastPage").click(function() {
		var depName = $("#depName-in-resultTable").val();
		var empNo = $("#empNo-in-resultTable").val();
		var startMonth = $("#startMonth-in-resultTable").val();
		var endMonth = $("#endMonth-in-resultTable").val();
		var salFrom = $("#salFrom-in-resultTable").val();
		var salTo = $("#salTo-in-resultTable").val();
		var offset = parseInt($(".totalPageNum").html()) - 1;
		var pageSize = parseInt($("#pageSize-in-resultTable").val());
		search(depName, empNo, startMonth, endMonth, salFrom, salTo, offset * pageSize, true);
	});
	
	//显示修改Modal
	var loadEditModel = function(rowId, result) {
		//var jsonData = eval('('+response+')');
		//var jsonData = eval(response);
		
		closeAlert();
		$(".fixedSalRow").remove();
		
		var row = result.datas[rowId];
		var fixedSalName = row.salItemName;
		
		var rowNum = 0;
		for (var i = 0; i < fixedSalName.length; i++) {
			if (i % 2 == 0) {
				var fixedSal = "<div id='fixedSalRow" + rowNum + "-in-editModal' class='fixedSalRow row'>";
				fixedSal += "<div class='col-xs-12 col-sm-6 col-md-5 col-md-push-1'>" +
							 "<div class='space space-4'></div><label class='salItemName'>" + fixedSalName[i] + "</label>" +
							 "<input id='fixedSal" + i + "-in-editModal' type='text' " +
							 "class='form-control fixedSalInput'/><div class='space space-4'></div></div>";
				$("#editModalFormBody").append(fixedSal);
			} else {
				var fixedSal = "<div class='col-xs-12 col-sm-6 col-md-5 col-md-push-1'>" +
							   "<div class='space space-4'></div><label class='salItemName'>" + fixedSalName[i] + "</label>" +
							   "<input id='fixedSal" + i + "-in-editModal' type='text' " +
							   "class='form-control fixedSalInput'/><div class='space space-4'></div></div>";
				$("#fixedSalRow" + rowNum + "-in-editModal").append(fixedSal);
				rowNum++;
			}
		}
		
		$("#depName-in-editModal").val(row.depName);
		$("#empNo-in-editModal").val(row.empNo);
		$("#empName-in-editModal").val(row.empName);
		$("#month-in-editModal").val(row.month);
		for (var i = 0; i < row.salItemValue.length; i++) {
			$("#fixedSal" + i + "-in-editModal").val(row.salItemValue[i]);
		}
		
		$(".fixedSalInput").blur(function() {
			salInput = $(this);
			for (var i = 0; i < salInput.length; i++) {
				validateNumberInput(salInput.eq(i));
			}
		});
	};
	
	//用户确认修改
	$("#confirmButton-in-editModal").click(function() {
		if ($("#editModalForm input.error").length == 0) {
			$("#editModal").modal('hide');
			
			var empNo = $("#empNo-in-editModal").val();
			var month = $("#month-in-editModal").val();
			var salItemName = $(".salItemName");
			var fixedSalName = new Array();
			for (var i = 0; i < salItemName.length; i++) {
				fixedSalName[i] = salItemName.eq(i).html();
			}
			var fixedSalInput = $(".fixedSalInput");
			var fixedSalValue = new Array();
			for (var i = 0; i < fixedSalInput.length; i++) {
				if (fixedSalInput.eq(i).val() == "") {
					fixedSalValue[i] = "*";
				} else {
					fixedSalValue[i] = fixedSalInput.eq(i).val();
				}
			}
			
			$.post("fixedSalary/updateFixedSal", 
					{"empNo":empNo, "month":month, "fixedSalName":fixedSalName, "fixedSalValue":fixedSalValue}, 
					function(response) {
						//console.log(response);
						//var jsonData = eval('('+response+')');
						var jsonData = eval(response);
						
						if (jsonData.statusCode != "200") {
							alertInfo($(".alertContainer"), jsonData.message);
						} 
						var depName = $("#depName-in-resultTable").val();
						var empNo = $("#empNo-in-resultTable").val();
						var startMonth = $("#startMonth-in-resultTable").val();
						var endMonth = $("#endMonth-in-resultTable").val();
						var salFrom = $("#salFrom-in-resultTable").val();
						var salTo = $("#salTo-in-resultTable").val();
						var pageNum = parseInt($(".pageNum").html()) - 1;
						var pageSize = parseInt($("#pageSize-in-resultTable").val());
						search(depName, empNo, startMonth, endMonth, salFrom, salTo, pageNum * pageSize, false);
					});
		}
	});
	
	// 在录入Modal的select元素中加chosen插件
	$("#importModal").on('shown.bs.modal', function () {
		$("select.importInput").chosen({
			no_results_text: "没有找到"
		});
	});
	
	// 使加了chosen插件的select元素实现响应式布局
	$(window).on('resize.chosen', function() {
	    var w = $('select').parent().width();
	    $('select').siblings('.chosen-container').css({'width':w});
	}).triggerHandler('resize.chosen');
	
	//显示录入Modal
	var loadImportModel = function(result) {
		//var jsonData = eval('('+response+')');
		//var jsonData = eval(response);
		
		closeAlert();
		$(".fixedSalRow").remove();
		$("#depName-in-importModal").val("");
		
		$("#empName-in-importModal").empty();
		$("#empName-in-importModal").append("<option value=''>请选择部门</option>");
		$("#empName-in-importModal").trigger("chosen:updated");
		$("#empName-in-importModal").val("");
		
		$("#startMonth-in-importModal").val("");
		$("#endMonth-in-importModal").val("");
		delValidateMsg($("#depName-in-importModal").siblings('.chosen-container'));
		delValidateMsg($("#empName-in-importModal").siblings('.chosen-container'));
		delValidateMsg($("#startMonth-in-importModal"));
		delValidateMsg($("#endMonth-in-importModal"));
		
		var fixedSalName = result.datas[0].salItemName;
		var rowNum = 0;
		for (var i = 0; i < fixedSalName.length; i++) {
			if (i % 2 == 0) {
				var fixedSal = "<div id='fixedSalRow" + rowNum + "-in-importModal' class='fixedSalRow row'>";
				fixedSal += "<div class='col-xs-12 col-sm-6 col-md-5 col-md-push-1'>" +
							 "<div class='space space-4'></div><label class='salItemName'>" + fixedSalName[i] + "</label>" +
							 "<input id='fixedSal" + i + "-in-importModal' type='text' " +
							 "class='form-control fixedSalInput'/><div class='space space-4'></div></div>";
				$("#importModalFormBody").append(fixedSal);
			} else {
				var fixedSal = "<div class='col-xs-12 col-sm-6 col-md-5 col-md-push-1'>" +
							   "<div class='space space-4'></div><label class='salItemName'>" + fixedSalName[i] + "</label>" +
							   "<input id='fixedSal" + i + "-in-importModal' type='text' " +
							   "class='form-control fixedSalInput'/><div class='space space-4'></div></div>";
				$("#fixedSalRow" + rowNum + "-in-importModal").append(fixedSal);
				rowNum++;
			}
		}
		
		// 加载部门列表
		$.get("fixedSalary/listDepName", 
				{}, 
				function(response) {
					//var jsonData = eval('('+response+')');
					var jsonData = eval(response);
					
					//console.log(jsonData);
					
					if (jsonData.statusCode != "200") {
						$("#importModal").modal('hide');
						alertInfo($(".alertContainer"), jsonData.message);
					}
					
					$("#depName-in-importModal").empty();
					$("#depName-in-importModal").append("<option value=''>请选择部门</option>");
					var result = jsonData.response;
					for (var i = 0; i < result.length; i++) {
						$("#depName-in-importModal").append("<option value='" + result[i].depId + "'>" + result[i].depName + "</option>");
					}
					$("#depName-in-importModal").trigger("chosen:updated");
				});
		
		// 根据选择的部门加载员工列表
		$("#depName-in-importModal").change(function() {
			var depId = $("#depName-in-importModal").val();
			if (depId != "") {
				$.post("fixedSalary/listEmpName", 
						{"depId":depId}, 
						function(response) {
							//var jsonData = eval('('+response+')');
							var jsonData = eval(response);
							
							//console.log(jsonData);
							
							if (jsonData.statusCode != "200") {
								$("#importModal").modal('hide');
								alertInfo($(".alertContainer"), jsonData.message);
							}
							
							$("#empName-in-importModal").empty();
							$("#empName-in-importModal").append("<option value=''>请选择员工</option>");
							var result = jsonData.response;
							for (var i = 0; i < result.length; i++) {
								$("#empName-in-importModal").append("<option value='" + result[i].empId + "'>" + result[i].empName + "</option>");
							}
							$("#empName-in-importModal").trigger("chosen:updated");
						});
			}
		});
		
		$(".fixedSalInput").blur(function() {
			salInput = $(this);
			for (var i = 0; i < salInput.length; i++) {
				validateNumberInput(salInput.eq(i));
			}
		});
		
		$(".importInput.date-picker").change(function() {
			validateRequiredInput($("#startMonth-in-importModal"));
			validateRequiredInput($("#endMonth-in-importModal"));
			
			var startMonth = $("#startMonth-in-importModal").val();
			var endMonth = $("#endMonth-in-importModal").val();
			if (startMonth != "" && endMonth != "") {
				if (startMonth > endMonth) {
					showValidateMsg($("#startMonth-in-importModal"), "开始月份不能大于结束月份", false);
				} else {
					showValidateMsg($("#startMonth-in-importModal"), "开始月份不能大于结束月份", true);
				}
			} else {
				showValidateMsg($("#startMonth-in-importModal"), "开始月份不能大于结束月份", true);
				validateRequiredInput($("#startMonth-in-importModal"));
				validateRequiredInput($("#endMonth-in-importModal"));
			}
			
		});
		
		$("select.importInput").change(function() {
			importInput = $(this);
			for (var i = 0; i < importInput.length; i++) {
				if (importInput.eq(i).val() != "") {
					showValidateMsg(importInput.eq(i).siblings('.chosen-container'), "请选择", true);
				} else {
					showValidateMsg(importInput.eq(i).siblings('.chosen-container'), "请选择", false);
				}
			}
		});
	};
	
	//用户确认录入
	$("#confirmButton-in-importModal").click(function() {
		importInput = $("select.importInput");
		for (var i = 0; i < importInput.length; i++) {
			if (importInput.eq(i).val() != "") {
				showValidateMsg(importInput.eq(i).siblings('.chosen-container'), "请选择", true);
			} else {
				showValidateMsg(importInput.eq(i).siblings('.chosen-container'), "请选择", false);
			}
		}
		validateRequiredInput($("#startMonth-in-importModal"));
		validateRequiredInput($("#endMonth-in-importModal"));
		if ($("#importModalForm [aria-invalid=true]").length == 0) {
			$("#importModal").modal('hide');
			
			var empId = $("#empName-in-importModal").val();
			var startMonth = $("#startMonth-in-importModal").val();
			var endMonth = $("#endMonth-in-importModal").val();
			
			var salItemName = $(".salItemName");
			var fixedSalName = new Array();
			for (var i = 0; i < salItemName.length; i++) {
				fixedSalName[i] = salItemName.eq(i).html();
			}
			var fixedSalInput = $(".fixedSalInput");
			var fixedSalValue = new Array();
			for (var i = 0; i < fixedSalInput.length; i++) {
				if (fixedSalInput.eq(i).val() == "") {
					fixedSalValue[i] = "*";
				} else {
					fixedSalValue[i] = fixedSalInput.eq(i).val();
				}
			}
			
			$.post("fixedSalary/addEmpFixedSal", 
					{"empId":empId, "startMonth":startMonth, "endMonth":endMonth, "fixedSalName":fixedSalName, "fixedSalValue":fixedSalValue}, 
					function(response) {
						//console.log(response);
						//var jsonData = eval('('+response+')');
						var jsonData = eval(response);
						
						if (jsonData.statusCode != "200") {
							alertInfo($(".alertContainer"), jsonData.message);
						} else {
							var depName = $("#depName-in-resultTable").val();
							var empNo = $("#empNo-in-resultTable").val();
							var startMonth = $("#startMonth-in-resultTable").val();
							var endMonth = $("#endMonth-in-resultTable").val();
							var salFrom = $("#salFrom-in-resultTable").val();
							var salTo = $("#salTo-in-resultTable").val();
							var pageNum = parseInt($(".pageNum").html()) - 1;
							var pageSize = parseInt($("#pageSize-in-resultTable").val());
							search(depName, empNo, startMonth, endMonth, salFrom, salTo, pageNum * pageSize, false);
						}
					});
		}
	});
	
	//用户点击导入按钮
	$("#importExcelButton").click(function() {
		closeAlert();
		$("#importExcelModal").modal('show');
		
		$("#startMonth-in-importExcelModal").val("");
		$("#endMonth-in-importExcelModal").val("");
		$("#file-in-importExcelModal").ace_file_input('reset_input');
		delValidateMsg($("#startMonth-in-importExcelModal"));
		delValidateMsg($("#endMonth-in-importExcelModal"));
		delValidateMsg($(".ace-file-input"));
		
		$(".importExcelInput.date-picker").change(function() {
			validateRequiredInput($("#startMonth-in-importExcelModal"));
			validateRequiredInput($("#endMonth-in-importExcelModal"));
			
			var startMonth = $("#startMonth-in-importExcelModal").val();
			var endMonth = $("#endMonth-in-importExcelModal").val();
			if (startMonth != "" && endMonth != "") {
				if (startMonth > endMonth) {
					showValidateMsg($("#startMonth-in-importExcelModal"), "开始月份不能大于结束月份", false);
				} else {
					showValidateMsg($("#startMonth-in-importExcelModal"), "开始月份不能大于结束月份", true);
				}
			} else {
				showValidateMsg($("#startMonth-in-importExcelModal"), "开始月份不能大于结束月份", true);
				validateRequiredInput($("#startMonth-in-importExcelModal"));
				validateRequiredInput($("#endMonth-in-importExcelModal"));
			}
		});
		
		$(".importExcelInput[type=file]").change(function() {
			
			var fileInput = $("#file-in-importExcelModal").val();
			if (fileInput != "") {
				showValidateMsg($(".ace-file-input"), "请选择", true);
			} else {
				showValidateMsg($(".ace-file-input"), "请选择", false);
			}
		});
	});
	
	//用户确认导入
	$("#confirmButton-in-importExcelModal").click(function() {
		validateRequiredInput($("#startMonth-in-importExcelModal"));
		validateRequiredInput($("#endMonth-in-importExcelModal"));
		var fileInput = $("#file-in-importExcelModal").val();
		if (fileInput != "") {
			showValidateMsg($(".ace-file-input"), "请选择", true);
		} else {
			showValidateMsg($(".ace-file-input"), "请选择", false);
		}
		
		if ($("#importExcelModalForm [aria-invalid=true]").length == 0) {
			$("#importExcelModal").modal('hide');
			var startMonth = $("#startMonth-in-importExcelModal").val();
			var endMonth = $("#endMonth-in-importExcelModal").val();
			$("#importExcelModalForm").ajaxSubmit({
				type: "POST",
				url: "fixedSalary/importFromExcel",
				success: function(response) {
					//console.log(response);
					//var jsonData = eval('('+response+')');
					var jsonData = eval(response);
					
					if (jsonData.statusCode != "200") {
						alertInfo($(".alertContainer"), jsonData.message);
					} else {
						var depName = $("#depName-in-resultTable").val();
						var empNo = $("#empNo-in-resultTable").val();
						var startMonth = $("#startMonth-in-resultTable").val();
						var endMonth = $("#endMonth-in-resultTable").val();
						var salFrom = $("#salFrom-in-resultTable").val();
						var salTo = $("#salTo-in-resultTable").val();
						var pageNum = parseInt($(".pageNum").html()) - 1;
						var pageSize = parseInt($("#pageSize-in-resultTable").val());
						search(depName, empNo, startMonth, endMonth, salFrom, salTo, pageNum * pageSize, false);
					}
				}
			});
		}
	});
	
	//验证是否填写必填项
	var validateRequiredInput = function(element) {
		if(element.val() != "") {
			showValidateMsg(element, "请选择", true);
		} else {
			showValidateMsg(element, "请选择", false);
		}
	};
	
	//验证输入是否为数字
	var validateNumberInput = function(element) {
		var regExp = /^[0-9]+.?[0-9]*$/;
		if(regExp.test(element.val()) || element.val() == "") {
			showValidateMsg(element, "请输入不小于零的数字", true);
		} else {
			showValidateMsg(element, "请输入不小于零的数字", false);
		}
	};
	
	//显示表单验证信息
	var showValidateMsg = function(element, msg, isValid) {
		if(!isValid) {
			element.removeClass("valid");
			element.addClass("error");
			element.attr("aria-invalid", true);
			if ($("#" + element.attr("id") + "-error").length > 0) {
				$("#" + element.attr("id") + "-error").html("<small>" + msg + "</small>");
				$("#" + element.attr("id") + "-error").css("display", "inline-block");
			} else {
				var errorLabel = "<label id='" + element.attr("id") + "-error' class='error' for='" + element.attr("id") + "' style=''>" +
						"<small>" + msg + "</small></label>";
				element.after(errorLabel);
			}
		} else {
			element.removeClass("error");
			element.addClass("valid");
			element.attr("aria-invalid", false);
			$("#" + element.attr("id") + "-error").css("display", "none");
		}
	};
	
	//删除表单验证信息
	var delValidateMsg = function(element) {
		$("#" + element.attr("id") + "-error").remove();
	};
	
	var alertInfo = function(container, msg) {
		container.css("display","none");
		container.html("");
		var div = "<div class='alert_div alert alert-warning alert-dismissible fade in' role='alert'>" +
				  "<button type='button' id='closeAlert' class='close' data-dismiss='alert' aria-label='Close'>" +
				  "<span aria-hidden='true'>×</span>" + "</button>" + "<strong class='show_ms'></strong>" +
				  "</div>";
		container.html(div);
		$(".show_ms").text(msg);
		container.css("display","");
		
		$("#closeAlert").click(function() {
			closeAlert();
		});
	};
	
	var closeAlert = function() {
		
		$(".alertContainer").html("");
		$(".alertContainer").css("display","none");
	};
	
});


